13. Exercise: Implement touchStart()
22 14 AAK TouchStart SC V2
Android Developer Documentation
Exercise
In this exercise you are going to implement touchStart().
- At the class level, add variables to cache the latest x and y values. After the user stops moving and lifts their touch, these are the starting point for the next path (the next segment of the line to draw).
private var currentX = 0f
private var currentY = 0f
- Implement the
touchStart()method as follows. Reset thepath, move to the x-y coordinates of the touch event (motionTouchEventXandmotionTouchEventY) and assigncurrentXandcurrentYto that value.
private fun touchStart() {
path.reset()
path.moveTo(motionTouchEventX, motionTouchEventY)
currentX = motionTouchEventX
currentY = motionTouchEventY
}